package gl.func.updoladPicture;

import gl.API;
import gl.App;

import java.io.File;
import java.io.FileInputStream;

import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

public class Upload {
	/**
	 * 通过HTTP上传图片到服务器
	 * @param filename 服务器接受到的文件名
	 * @param file 欲上传的本地文件
	 */
	public static void uploadFile(String filename, File file,AjaxCallBack<?> ajaxcallback) {
		AjaxParams ap = new AjaxParams();
		try {
			ap.put("filename", new FileInputStream(file), filename);
			App.mFinalhttp.post(API.URL_UPLOAD, ap, ajaxcallback);
		} catch (Exception e) {
			e.printStackTrace();
			ajaxcallback.onFailure(e, 0, "");
		}
	}

}
